/**
 *
 */
package com.china.lee.getpi;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * The Class getPiFromRandom.
 * 
 * @author li-l
 */
public class getPiFromRandom {

	/**
	 * The main method.
	 * 
	 * @param args the arguments
	 */
	public static void main(String[] args) {
		long n = 100;
		System.out.println("please input number:");
		try {
			BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
			n = Long.valueOf(reader.readLine());
		} catch (IOException ex) {
		} catch (Exception ex) {
		}
		int scale = 100;
		System.out.println("please input scale(number):");
		try {
			BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
			scale = Integer.valueOf(reader.readLine());
		} catch (IOException ex) {
		} catch (Exception ex) {
		}

		long goodCount = 0;
		for (int i = 0; i < n; i += 1) {
			double x = Math.random();
			double y = Math.random();
			if (Math.pow(x - 0.5, 2)
					+ Math.pow(y - 0.5, 2) <= 0.25) {
				goodCount++;
			}
		}
		BigDecimal pi =
				new BigDecimal(4.0).multiply(new BigDecimal(goodCount * 1.0).divide(new BigDecimal(n * 1.0),
						scale,
						RoundingMode.UP));
		System.out.println("Pi is:"
				+ pi.toString());
		System.out.println("SYS Pi is:"
				+ Math.PI);
	}

}
